import { DocumentRegistry } from '@jupyterlab/docregistry';

import { Contents } from '@jupyterlab/services';

import { MindElixirDocModel } from './mindElixirModel';
import { MindElixirDoc } from './mindElixirDoc';

export interface IDocModelFactoryOpts {
    modelName: string;
    contentType: Contents.ContentType; 
    fileFormat: Contents.FileFormat;
}

export class DocModelFactory implements DocumentRegistry.IModelFactory<MindElixirDocModel> {
    private _disposed = false;
    private _modelName: string = "mind-elixir-file"
    private _contentType: Contents.ContentType = 'application/json' as any;
    private _fileFormat: Contents.FileFormat = 'json' as any;

    constructor(opt: IDocModelFactoryOpts) {
        this._disposed = false;

        this._modelName = opt.modelName;
        this._contentType = opt.contentType;
        this._fileFormat = opt.fileFormat;
    }

    /**
     * The name of the model.
     *
     * @returns The name
     */
    get name(): string {
        return this._modelName;
    }

    /**
     * The content type of the file.
     *
     * @returns The content type
     */
    get contentType(): Contents.ContentType {
        return this._contentType;
    }

    /**
     * The format of the file.
     *
     * @returns the file format
     */
    get fileFormat(): Contents.FileFormat {
        return this._fileFormat;
    }

    /**
     * 不允许协作编辑思维图文档，因为MindElixirDoc不支持协作编辑。
     */
    readonly collaborative: boolean = false;

    /**
     * Get whether the model factory has been disposed.
     *
     * @returns disposed status
     */
    get isDisposed(): boolean {
        return this._disposed;
    }

    /**
     * Dispose the model factory.
     */
    dispose(): void {
        this._disposed = true;
    }

    /**
     * Get the preferred language given the path on the file.
     *
     * @param path path of the file represented by this document model
     * @returns The preferred language
     */
    preferredLanguage(path: string): string {
        return '';
    }

    /**
     * Create a new instance of ExampleDocModel.
     *
     * @param languagePreference Language
     * @param modelDB Model database
     * @param isInitialized - Whether the model is initialized or not.
     * @param collaborationEnabled - Whether collaboration is enabled at the application level or not (default `false`).
     * @returns The model
     */
    createNew(
        options: DocumentRegistry.IModelOptions<MindElixirDoc>
    ): MindElixirDocModel {
        console.log("DocModelFactory createNew called.")    
        return new MindElixirDocModel(options);
    }
}